Skip to content

refactor(pptx): move font embedding out of PptxRenderEnvironment - #1082

Merged
DemchaAV merged 2 commits into
developfrom
refactor/pptx-split-render-environment
Nov 23, 2026
Merged

DemchaAV merged 2 commits into
developfrom
refactor/pptx-split-render-environment

Conversation

@DemchaAV

@DemchaAV DemchaAV commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Why

PptxRenderEnvironment is the per-render state every PPTX handler draws through: slide surfaces, transform groups, pictures and navigation records. Font embedding grew inside it until it was most of the file: 1,426 lines on develop, against the project's 500. Embedding is a responsibility of its own:

  • which registered families a deck carries;
  • the viewer family a run is written with;
  • refusing a family whose faces cannot all travel;
  • the slot ledger shared across families;
  • the bundled pass after the last slide;
  • the log lines about a family the deck does not carry.

What changed

Four package-private types in com.demcha.compose.document.backend.fixed.pptx take the font code:

  • PptxDeckFonts (433 lines) — the fonts of one render:
    • the registered-family pass the environment's constructor used to run;
    • fontFamily(...) with its render.pptx.font.substitution lines;
    • tokensTheNameMaySpeak and the viewer metrics by family;
    • embedsBundledFonts(boolean) and embedBundledFontsUsed();
    • the two warn… methods.
  • PptxFontEmbedder (487 lines, static) — embedFontFamilyWithMetrics, embedFontFamily, readPrograms, claimSlotsAndReportSharing, handOverPrograms and the FamilyPrograms record. With them go the embed.skipped, shared.family and name.mismatch lines they write.
  • PptxSlotLedger (133 lines) — the former PptxRenderEnvironment.SlotLedger. The Seated record, a sibling of it in the environment, now sits inside it.
  • PptxFontFace (29 lines) — the four faces of a family, the former PptxRenderEnvironment.Face, shared by the two classes above.

PptxRenderEnvironment (471 lines) holds a PptxDeckFonts and delegates to it. fontFamily(...), runIsBold/runIsItalic, viewerAscent and the two package-private bundled-font methods keep their signatures, so no handler or caller changes. Public API is unchanged and the knowledge pack is untouched.

The moved code is the original lines, sliced from the file rather than retyped. Every non-blank line of the original is accounted for in the new files. What differs:

  • visibility: private → package-private where another class now calls a member;
  • the names the move changes: SlotLedger → PptxSlotLedger, Face → PptxFontFace, calls qualified with PptxFontEmbedder.;
  • javadoc references that now cross a class, and rewrapped javadoc lines.

What is new is the wiring:

  • the class javadocs;
  • PptxDeckFonts' constructor and its viewerMetrics(FontName) accessor;
  • PptxFontEmbedder's private constructor;
  • the environment's delegating methods.

Documentation:

  • CHANGELOG.md (2.5.2, Internal);
  • docs/architecture/backend-capability-details.md and the javadoc of DocxFontTable, PptxFontMapping and PptxEmbeddedFont now name the classes the code lives in.

Verification

I compared deck bytes and the render log before (develop at eb80150ef) and after, using a throwaway probe test that is not committed:

  • 20 decks rendered with deterministic(...) are identical by SHA-256. They cover:

    • standard-14 text and bundled scripts;
    • a registered three-face family and a family without sources;
    • two families colliding on one slot, and two sharing a name without colliding;
    • a truncated font beside a carrier, and a missing file registered twice;
    • a single-face -Bold registration, and a registration under a bundled family's viewer name;
    • AsapCondensed's name mismatch;
    • pictures, links, bookmarks, a duplicate anchor, a rasterized clip and a sectioned deck.

    Each was rendered with bundled embedding on and off where that matters.

  • 259 render-log lines, captured at DEBUG while those decks rendered, are the same text in the same order (timings masked).

  • The 6 demo decks written by the module's parity tests: all 245 parts are identical by SHA-256. docProps/core.xml, which carries the time, is excluded.

The probe has no deck where two faces of one definition read back as one slot, and none with a face whose licence forbids embedding. Those paths are covered by the unit tests and the sabotage below.

Sabotage: 8 of 8 caught. Each sabotage breaks one moved responsibility and is run against its own single test (Tests run: 1, Failures: 1 every time). Sources are restored and SHA-checked afterwards. The eight are: the run path's ledger question in PptxDeckFonts.fontFamily; reporting a registered family once per name; the cross-family slot refusal in readPrograms; the ledger's case-insensitive match; runIsBold's delegation; viewerAscent's viewer metrics; the bundled pass's delegation; and the shared-name warning.

Module runs on the final tree:

  • ./mvnw -B -ntp test -pl :graph-compose-render-pptx -am — 205 run, 0 failed — the same 205 as on develop.
  • ./mvnw -B -ntp test -f qa/pom.xml, after installing — 1926 run, 0 failed, 1 skipped.

The full local gate runs before this leaves draft.

PptxRenderEnvironment had grown to 1,426 lines, most of them the
embedding of registered and bundled font families. The embedding now
lives in package-private classes beside it:

- PptxDeckFonts: which registered families the deck carries, the viewer
  family a run is written with, the faces the runs drew, the bundled
  pass after the last slide, and the render.pptx.font.substitution
  lines;
- PptxFontEmbedder: reading a family's faces, refusing it whole, claiming
  its style slots and handing the programs to the presentation, with the
  embed.skipped, shared.family and name.mismatch lines;
- PptxSlotLedger: which face holds each style slot of a declared viewer
  family, with the Seated record;
- PptxFontFace: a family's four faces, shared by the two above.

The environment keeps every public method; the font ones delegate. The
moved code is the original lines; what differs is visibility, the names
the move changes and the javadoc references that now cross a class.

No behaviour change: decks rendered with deterministic(...) are the same
bytes, and the render log carries the same lines in the same order.
…says

The CHANGELOG entry counted three classes beside PptxRenderEnvironment
where the split made four, PptxFontFace included, and said the
shared.family and name.mismatch lines name why a face did not travel;
only embed.skipped does. Two long lines rewrapped.
@DemchaAV
DemchaAV marked this pull request as ready for review November 23, 2026 11:26
@DemchaAV
DemchaAV merged commit 6ec0d74 into develop Nov 23, 2026
13 checks passed
@DemchaAV
DemchaAV deleted the refactor/pptx-split-render-environment branch November 23, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant